/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




package learn.round1A;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import org.omg.CORBA.INTERNAL;

/**
 *
 * @author robit
 */
public class MakeitSmooth {
    int D,I,M;
    LinkedList<Integer> pixs;
    MakeitSmooth(int D,int I,int M,LinkedList<Integer> pixs){
        this.D=D;
        this.I=I;
        this.M=M;
        this.pixs=pixs;
    }
    int insertCost(int x1,int x2){
        int d=Math.abs(x1-x2);
        if(d<=M) return 0;
        return M==0?255*I:(d-1)/M*I;
    }
    int insertCost(LinkedList<Integer> pixs){
        int cost=0;
        for (int i=0; i < pixs.size()-1;i++) {
            cost+=insertCost(pixs.get(i),pixs.get(i+1));
        }
        return cost;
    }
    int changeCost(LinkedList<Integer> oldpixs,LinkedList<Integer> newpixs){
        int sum=0;
        for (int i=0; i < oldpixs.size();i++) {
            sum+=Math.abs(oldpixs.get(i)-newpixs.get(i));
        }
        return sum;
    }
    int getCost(LinkedList<Integer> pixs){
        if(pixs.size()==0)return 0;//System.out.println(60);
        
        int radius=insertCost(pixs);//System.out.println(62);
        int mincost=radius;
        radius=Math.min(radius, 255);

        LinkedList<LinkedList> generator=new LinkedList<LinkedList>();
        generator.add(new LinkedList<Integer>());
        
        int counter=0;
        while(!generator.isEmpty()){
            
            LinkedList<Integer> e = generator.poll();

//            if(counter++%1000==0){
//                System.out.println(radius);
//                System.out.println(counter);
//                System.out.println(e.size());
//                System.out.println(generator.size());
//            }
            if(e.size()<pixs.size()){
                int pn=pixs.get(e.size());
                for(int i=-radius;i<=radius;i++){
                    if(pn+i>=0&&pn+i<256){
                       LinkedList ne=null;
                            ne=(LinkedList)e.clone();
                            ne.add(pn+i);
                            generator.add(ne);

                        
                    }
                }
            }else{
                mincost=Math.min(mincost, insertCost(e)+changeCost(pixs,e));
            }

        }

        for (int i=0; i < pixs.size();i++) {
            LinkedList<Integer> subpixs = (LinkedList<Integer>)pixs.clone();
            if(insertCost(subpixs)+D<mincost){
                subpixs.remove(i);
                mincost=Math.min(mincost, getCost(subpixs)+D);
            }
        }
        return mincost;
    }
    int getCost(){
        return getCost(pixs);
    }

    private static Scanner s = null;
    private static PrintWriter o = null;
    /**
    * calculate the answer
    */
    private static String reckon() {
        int D=Int();
        int I=Int();
        int M=Int();
        int N=Int();
        //int[] pixs=new int[N];
       LinkedList<Integer> pixs= new LinkedList<Integer>();
        for (int i = 0; i < N; i++) {
            pixs.add(Int());
        }
       
        System.out.println("finish Case");
        return Integer.toString(new MakeitSmooth(D, I, M, pixs).getCost());
    }


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here

        try {
            //String filename="test";
           String prob="B";
           String filename=prob+"-small-practice";
            //String filename=prob+"-large-practice";

            s = new Scanner(
                    new BufferedReader(new FileReader(filename+".in")));
            //s.useLocale(Locale.US);
            o = new PrintWriter(
                    new BufferedWriter(new FileWriter(filename+".out")));

            // Determine input line number
            int lineNums = s.nextInt();

            for (int i = 1; i <= lineNums; i++) {
                o.println("Case #" + i + ": " + reckon());
            }
        } finally {
            s.close();
            o.close();
        }
    }


    private static int Int(){
        return s.nextInt();
    }
    private static long Long(){
        return s.nextLong();
    }
    private static String String(){
        return s.next();
    }

}
